package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class AddCommentHandleListener {

    @Autowired
    private ApArticleService apArticleService;

    @KafkaListener(topics = ArticleConstants.ARTICLE_ADD_COMMENT_TOPIC)
    public void onMessage(String mess){
        if(StringUtils.isNotBlank(mess)){
            Long articleId = JSON.parseObject(mess, Long.class);
            apArticleService.AddComment(articleId);

        }
    }
}